package com.cosyhut.blocks.display;

import java.util.logging.Level;

import com.jme.system.DisplaySystem;
import com.jme.system.JmeException;
import com.jme.system.PropertiesIO;
import com.jme.util.LoggingSystem;

/**
 * 
 * @author TimWorks
 * Jav 25, 2007
 * 
 * Handle the OS/Windows related staff
 *
 */
public class GWindow {
    private DisplaySystem _display;
    private PropertiesIO _properties;

//    private int _width = 640;
//    private int _height = 360;
    private int _width = 128;
    private int _height = 96;
    
    public GWindow() {
        try {
            this._properties = new PropertiesIO("");
            this._display = DisplaySystem.getDisplaySystem(this._properties
                    .getRenderer());
            LoggingSystem.getLogger().log(
                    Level.INFO,
                    "Running on: " + this._display.getAdapter()
                            + "\nDriver version: "
                            + this._display.getDriverVersion());

            int alphaBits = 0;
            int depthBits = 8;
            int stencilBits = 0;
            int samples = 0;
            this._display.setMinDepthBits(depthBits);
            this._display.setMinStencilBits(stencilBits);
            this._display.setMinAlphaBits(alphaBits);
            this._display.setMinSamples(samples);

            /** Create a window with the startup box's information. */
            this._display.createWindow(this._width, this._height, 32, 60, false);
        } catch (JmeException e) {
            /**
             * If the displaysystem can't be initialized correctly, exit
             * instantly.
             */
            e.printStackTrace();
            System.exit(1);
        }

        this._display.setTitle("Blocks!");

    }
    
    public DisplaySystem getDisplay() {
        return this._display;
    }

    public int getWidth() {
        return this._width;
    }
    public int getHeight() {
        return this._height;
    }
    
    public boolean isClosing() {
        return this._display.isClosing();
    }
    
    public void close() {
        this._display.reset();
        if (this._display != null) {
            this._display.close();
        }
    }
}
